package cn.virens.web.components.shiro.simple.ajax;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.web.filter.authc.UserFilter;
import org.springframework.web.cors.CorsUtils;

public class AjaxUserFilter extends UserFilter {
	@Override
	protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
		return CorsUtils.isPreFlightRequest((HttpServletRequest) request) || super.preHandle(request, response);
	}

	@Override
	protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
		return AjaxUtil.write(request, response, AjaxUtil.failed("NoLogin", "请登录"));
	}
}
